package com.AUI
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;

	/**
	 * Here provide same objects and methods for AUI component in private.
	 * <p>Note: Third part developer don't use it.</p>
	 * @private
	 * @author HuangMinPing
	 * @site www.AminLab.com
	 */
	public class AUIPrivate
	{
		/**
		 * Pre-selector names.
		 */
		static public const BDM:Matrix = new Matrix;
		/**
		 * Pre-selector names.
		 */
		static private var _psn:Vector.<String> = new Vector.<String>;
		/**
		 * Global event dispatcher.
		 */
		static public const ED:EventDispatcher = new EventDispatcher;
		/**
		 * This BitmapData for fix scrollRect bug.
		 */
		static public const BD:BitmapData = new BitmapData(1,1);
		/**
		 * [cache]
		 */
		static public const CMD:Vector.<int> = Vector.<int>([GraphicsPathCommand.MOVE_TO,GraphicsPathCommand.LINE_TO,GraphicsPathCommand.LINE_TO,GraphicsPathCommand.LINE_TO]);
		/**
		 * [cache]
		 */
		static public const BPT:Vector.<Number> = new Vector.<Number>(8);
		/**
		 * This flag for debug some component when need.
		 */
		static public var DEBUG:Boolean = false;
		/**
		 * Show rect.
		 */
		static public var SHOWRECT:Rectangle = new Rectangle(0,0,10,10);
		/**
		 * full rect.
		 */
		static public var FULLRECT:Rectangle = new Rectangle(0,0,100,100);
		/**
		 * Current global unique usable number.
		 */
		static private var _gun:uint = 0x80000000; // 2147483648
		/**
		 * Increase global unique usable number and return.This function normally be used in some AUI components,like number of AGroupButton items of AList.
		 */
		static public function incGUN():uint
		{
			if(_gun == 0xFFFFFFFF)
			{
				throw new Error('No enough __ID__,may be you must modify source code to fill your requirements');
			}
			++ _gun;
			return _gun;
		}
		/**
		 * Add one or more pre-selectors to AGlobalManager for use in next component has being created.
		 * @param ...strings one or more selector names
		 */
		static public function addPreSelectorNames(...strings):void
		{
			for(var i:int = 0,len:int = strings.length;i < len;++i)
			{
				_psn.push(strings[i]);
			}
		}
		/**
		 * Get a pre-selectors from AGlobalManager.Normally this function be called by AUI,you don't need call it.
		 */
		static public function getPreSelectorName():String
		{
			return _psn.pop();
		}
		static public function sliceBitamp(source:BitmapData,width:int,height:int,left:int,top:int,right:int,bottom:int):BitmapData
		{
			if(width == 0 || height == 0 || (left == 0 && top == 0 && right == 0 && bottom == 0))
			{
				return source;
			}
			var bmpData:BitmapData = new BitmapData(width,height,true,0x00000000);
			var sRows:Array = [0, top,  bottom, source.height];
			var sCols:Array = [0, left, right,  source.width];
			var dRows:Array = [0, top,  height - (source.height - bottom), height];
			var dCols:Array = [0, left, width  - (source.width - right), width];
			var src:Rectangle;
			var dst:Rectangle;
			var mat:Matrix = new Matrix;
			for(var cx:int = 0;cx < 3;cx++)
			{
				for(var cy:int = 0;cy < 3;cy++)
				{
					src = new Rectangle(sCols[cx], sRows[cy], sCols[cx + 1] - sCols[cx], sRows[cy + 1] - sRows[cy]);
					dst = new Rectangle(dCols[cx], dRows[cy], dCols[cx + 1] - dCols[cx], dRows[cy + 1] - dRows[cy]);
					mat.identity();
					mat.a  = dst.width  / src.width;
					mat.d  = dst.height / src.height;
					mat.tx = dst.x - src.x * mat.a;
					mat.ty = dst.y - src.y * mat.d;
					bmpData.draw(source,mat,null,null,dst);
				}
			}
			return bmpData;
		}
	}
}